package controllers

import (
	"github.com/astaxie/beego"
	//"fmt"
	"beego/testApp/common/student"
	"beego/testApp/common/class"
	"beego/testApp/common/tool"
	
	"time"
	
)

type AddStudentController struct {
	beego.Controller
}

func (c *AddStudentController) Get() {

	cid,_ := c.GetInt("cid")
	sname := c.GetString("sname")
	sage,_  := c.GetInt("sage")
	sgender := c.GetString("sgender")
	sprovince := c.GetString("sprovince")
	created := time.Now()

	tool.Pic("add student get input param  ", sgender)

	if(cid != 0 && sname != "" && sage !=0  && sgender != "" && sprovince != "" ){
		
		
       

		 studenttemp := &student.Student{Cid:cid,Sname:sname,
			Age:sage,Province:sprovince,Gender:sgender,Created:created}

		 tool.Pic("add student start",studenttemp)
		
		 ck := studenttemp.Add()  
		 if(ck == true){

			c.Redirect("/admin/classlist",301)
		 }

	}


	classobj := class.Class{}

	classlist := classobj.GetClassList(0)

	c.Data["clist"] = classlist
	
	tool.Pic("add student get class list ",classlist)
	 
	c.TplName = "addstudent.html"
}
